package freejim.icu.highschoolhealthstatuspost.service;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import freejim.icu.highschoolhealthstatuspost.dao.DailyPost;
import freejim.icu.highschoolhealthstatuspost.dao.DailyPostRepository;
import freejim.icu.highschoolhealthstatuspost.dao.DetailInfo;
import freejim.icu.highschoolhealthstatuspost.dao.DetailInfoRepository;
import org.springframework.boot.jackson.JsonObjectDeserializer;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

@Service
public class AnalyseService {
    @Resource
    DailyPostRepository dailyPostRepository;

    public List<DailyPost> getUnNormalTemperatureList(){
        return dailyPostRepository.getUnNormalTemperatureList();
    }
    public List<DailyPost> getDangerTripList(){
        return dailyPostRepository.getDangerTripList();
    }
    public String buildCSV(JSONArray array) throws IOException {
        StringBuilder csv_content = new StringBuilder("姓名,联系方式\n");
        int length = array.size();
        for (int i=0;i<length;i++){
            JSONObject jsonObject = array.getJSONObject(i);
            String name = (String)jsonObject.get("name");
            String phonenumber = (String)jsonObject.get("phonenumber");
            csv_content.append(name+","+phonenumber+"\n");
        }
        System.out.println(csv_content);
        return csv_content.toString();
    }
}
